/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nanosn.coffeemaker.freemarker;

import fmpp.ProcessingException;
import fmpp.progresslisteners.ConsoleProgressListener;
import fmpp.setting.SettingException;
import fmpp.setting.Settings;
import fmpp.util.MiscUtil;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * A class to interface with the FMPP command line utility.
 * @author selkhateeb
 */
public class FMPP
{

    /**
     * Runs the FMPP templating engine.
     * Pre: the sourceDirectory exists and contains templates.
     * Post: The destination directory has been created and all templates has
     *       been processed.
     * @param sourceDirectory
     * @param destinationDirectory
     * @param dataMap
     */
    @SuppressWarnings("unchecked")
    public static void RunFMPP(String sourceDirectory,
                               String destinationDirectory,
                               Map dataMap)
    {
        try
        {
            Settings ss = new Settings(new File("."));
            //ss.load(cfgFile);
            ss.set("sourceRoot", sourceDirectory);
            ss.set("outputRoot", destinationDirectory);


//            Map data = new HashMap(1);
//            data.put("ProjectName", "database");


            ss.set("data", dataMap);

            ss.addProgressListener(new ConsoleProgressListener());

            ss.execute();
            System.out.println("Done.");
        }
        catch (SettingException e)
        {
            System.err.println(MiscUtil.causeMessages(e));
            System.exit(-2);
        }
        catch (ProcessingException e)
        {
            System.err.println(MiscUtil.causeMessages(e));
            System.exit(-3);
        }

    }
}
